/**
 * Created by Administrator on 2017/12/6.
 */
import React,{Component} from 'react';
import {render} from 'react-dom';

class Mtable extends Component {
     constructor(props){
        super(props)
        this.state={ttt: "",aaa:"18"};

    }

    componentDidMount(){/*组件渲染完毕*/
        debugger;
        var _this=this;
        window.fetch(this.props.url)/*获取persons.json的数据*/
            .then(function(rep){/*取到之后做什么*/
            if(rep.ok){/*如果获取成功*/
               return  rep.json().then(function(jjs){/*如果成功获取数据就进行如下操作*/
                     return jjs.map(function(item,index){
                          return (
                            <tr key={index}>
                                <td>{item.name}</td>
                                <td>{item.age}</td>
                                <td>{item.duanwei}</td>
                            </tr>
                            )
                })

                });
            }
        }).then(function(txt){
            _this.setState({"ttt":txt})
        });
    }
    render() {

        return (
            <div>
                <h1>{this.props.tt}</h1>
                <h2>{this.state.aaa}</h2>
            <table border="1">
                <tbody>
                <tr>
                    <td>姓名</td>
                    <td>年龄</td>
                    <td>段位</td>
                </tr>
                {this.state.ttt}


                </tbody>
            </table>
                </div>
        );
    }
}

export default Mtable;